﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Data.Linq.Mapping;
using System.Data.Linq;

namespace Organizer.Model
{
    [Table]
    public class CategoryTask : Base<CategoryTask>
    {
        [Column(IsPrimaryKey = true, DbType = "UniqueIdentifier NOT NULL", CanBeNull = false, AutoSync = AutoSync.OnInsert, UpdateCheck = UpdateCheck.Never)]
        public Guid Id { get; private set; }

        [Column]
        internal Guid _categoryId;
        private EntityRef<Category> _category;
        /// <summary>
        /// Ссылка на категорию
        /// </summary>
        [Association(Storage = "_category", ThisKey = "_categoryId", OtherKey = "Id", IsForeignKey = true)]
        public Category Category
        {
            get { return _category.Entity; }
            set
            {
                NotifyPropertyChanging(() => this.Category);
                _category.Entity = value;
                if (value != null) _categoryId = value.Id;
                NotifyPropertyChanged(() => this.Category);
            }
        }

        [Column]
        internal Guid _taskId;
        private EntityRef<Task> _task;
        /// <summary>
        /// Ссылка на задачу
        /// </summary>
        [Association(Storage = "_task", ThisKey = "_taskId", OtherKey = "Id", IsForeignKey = true)]
        public Task Task
        {
            get { return _task.Entity; }
            set
            {
                NotifyPropertyChanging(() => this.Task);
                _task.Entity = value;
                if (value != null) _taskId = value.Id;
                NotifyPropertyChanging(() => this.Task);
            }
        }
    
        public CategoryTask()
        {
            Id = Guid.NewGuid();
        }

        public CategoryTask(Task pTask, Category pCategory)
            : this()
        {
            Task = pTask;
            Category = pCategory;
        }
    }
}
